package com.supercube.system.controller;

import com.supercube.common.utils.CubeUtils;
import com.supercube.sport.yoga.utils.ResultInfo;
import com.supercube.system.domain.SysProvCityDistDO;
import com.supercube.system.service.SysProvCityDistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@RequestMapping("/sysProvCityDist")
@Controller
@Api(tags = "系统省市区县")
public class SysProvCityDistController {

    @Autowired
    SysProvCityDistService sysProvCityDistService;

    @ApiOperation(value = "获取所有省市区县树", notes = "获取所有省市区县树")
    @ResponseBody
    @PostMapping("/queryTreeAllProvCityDist")
    ResultInfo queryTreeAllProvCityDist() {
        List<SysProvCityDistDO> provinceDistList = sysProvCityDistService.queryAllProvCityDist();

        try {
            List<SysProvCityDistDO> tree = CubeUtils.getTree(provinceDistList, "id");
            return ResultInfo.success(tree);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.failed("查询失败");
    }

    @ApiOperation(value = "获取所有省市区县", notes = "获取所有省市区县")
    @ResponseBody
    @PostMapping("/queryAllProvCityDist")
    ResultInfo queryAllProvCityDist() {
        List<SysProvCityDistDO> provinceDistList = sysProvCityDistService.queryAllProvCityDist();
        return ResultInfo.success(provinceDistList);
    }

    @ApiOperation(value = "获取所有省", notes = "获取所有省")
    @ResponseBody
    @PostMapping("/queryAllProvinceDist")
    ResultInfo queryAllProvinceDist() {
        List<SysProvCityDistDO> provinceDistList = sysProvCityDistService.queryAllProvinceDist();
        return ResultInfo.success(provinceDistList);
    }

    @ApiOperation(value = "根据省id获取所有地市", notes = "根据省id获取所有地市")
    @ResponseBody
    @PostMapping("/queryAllCityDistByProvinceId")
    ResultInfo queryAllCityDistByProvinceId(@RequestParam("provinceId") String provinceId) {
        List<SysProvCityDistDO> cityDistList = sysProvCityDistService.queryAllCityDistByProvinceId(provinceId);
        return ResultInfo.success(cityDistList);
    }

    @ApiOperation(value = "根据地市id获取所有区县", notes = "根据地市id获取所有区县")
    @ResponseBody
    @PostMapping("/queryAllCityDistByCityId")
    ResultInfo queryAllCityDistByCityId(@RequestParam("cityId") String cityId) {
        List<SysProvCityDistDO> cityDistList = sysProvCityDistService.queryAllCityDistByCityId(cityId);
        return ResultInfo.success(cityDistList);
    }
}
